import Express from "express";
import EmailCodeService from "../../service/EmailCodeService";
import ResponseHelper from "../utils/ResponseHelper";
import { ITokenRequest } from "../tokenMiddleware";

const router = Express.Router();

// 注册邮箱验证码
router.post("/code", async (req, res, next) => {
  try {
    const result = await EmailCodeService.create(
      (req.body.email as string) || ""
    );
    ResponseHelper.send(result, res, req as ITokenRequest);
  } catch (err) {
    next(err);
  }
});

// 修改密码邮箱验证码
router.post("/modifyPassword/code", async (req, res, next) => {
  try {
    const result = await EmailCodeService.create(
      (req.body.email as string) || "",
      "修改密码"
    );
    ResponseHelper.send(result, res, req as ITokenRequest);
  } catch (err) {
    next(err);
  }
});

export default router;
